package com.project.service.impl;

import com.project.bean.ShopCarBean;
import com.project.mapper.IShopCarMapper;
import com.project.service.IShopCarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author lyl
 * description:
 */
@Service
@Transactional
public class ShopCarServiceImpl implements IShopCarService {
    @Autowired
    private IShopCarMapper iShopCarMapper;

    @Override
    public void add(int productId, int userId) {
        ShopCarBean shopCarBean = iShopCarMapper.findShopCarById(productId, userId);
        if (shopCarBean != null) {
            iShopCarMapper.updateProductToShopCar(productId, userId);
        } else {
            iShopCarMapper.addNewProductToShopCar(productId, userId);
        }
    }

    @Override
    public void delProductFromShopCar(int productId, int userId) {
        iShopCarMapper.delProductFromShopCar(productId, userId);
    }

    @Override
    public void updateProductNum(int shopCarId, int num) {
        iShopCarMapper.updateProductNum(shopCarId, num);
    }

    @Override
    public List<ShopCarBean> findAllByUserId(int userId) {
        return iShopCarMapper.findAllByUserId(userId);
    }
}
